package ar.edu.itba.pod.legajo48240.event;

import java.io.Serializable;
import java.rmi.RemoteException;

import org.apache.log4j.Logger;

import ar.edu.itba.event.EventInformation;
import ar.edu.itba.pod.agent.runner.Agent;
import ar.edu.itba.pod.legajo48240.model.Host;
import ar.edu.itba.pod.legajo48240.node.ClusterManager;
import ar.edu.itba.pod.multithread.MultiThreadEventDispatcher;

public class LocalEventDispatcher extends MultiThreadEventDispatcher {


	private static final Logger LOGGER = Logger.getLogger(ClusterManager.class);
	
	private final Host localhost;
	
	public LocalEventDispatcher(Host host) {
		this.localhost=host;
	}	
	
	public void localPublish(Agent source, Serializable event) throws InterruptedException {
		super.publish(source,event);
	}
	
	@Override
	public void publish(Agent source, Serializable event) throws InterruptedException {
		
		EventInformation eventInformation=new EventInformation(event, localhost.id(), source);
		eventInformation.setReceivedTime(System.nanoTime());
		
		try {
			localhost.dispatcher().publish(eventInformation);
		} catch (RemoteException ignore) {} // local method
	}
}
